ATmega 328p
/* Name : main.c * Purpose : Source code for Keypad Interfacing with Arduino. * Author : Gemicates * Date : 18-01-2018 * Website : www.gemicates.org * Revision : None */ #include<LiquidCrystal.h> // this header file has instructions written in it, which enables // the user to interface an LCD to UNO in 4 bit mode without any fuzz LiquidCrystal lcd(8, 9, 10, 11, 12, 13); // sets the interfacing pins int R1=0; // declares R1, R2, R3, R4, C1, C2, C3, C4, int R2=1; // D4, D5, D6, D7 as integer type int R3=2; int R4=3; int C1=4; int C2=5; int C3=6; int C4=7; int D4; int D5; int D6; int D7; void setup() { pinMode(R1,OUTPUT); // initialize the digital pins R1, R2, R3, R4 as outputs pinMode(R2,OUTPUT); pinMode(R3,OUTPUT); pinMode(R4,OUTPUT); pinMode(C1,INPUT); // initialize the digital pins C1, C2, C3, C4 as inputs pinMode(C2,INPUT); pinMode(C3,INPUT); pinMode(C4,INPUT); digitalWrite(C1,HIGH); // Drive C1, C2, C3, C4 to HIGH digitalWrite(C2,HIGH); digitalWrite(C3,HIGH); digitalWrite(C4,HIGH); lcd.begin(16, 2); // initializes the 16*2 LCD lcd.setCursor(0,0); // sets the cursor at row 0 column 0 lcd.print("16*2 LCD MODULE"); // prints 16*2 LCD MODULE } void loop() { lcd.setCursor(0,1); // sets the cursor at row 0 column 1 digitalWrite(R1,LOW); // Drive R1 to LOW digitalWrite(R2,HIGH); // Drive R2, R3 ,R4 to HIGH digitalWrite(R3,HIGH); digitalWrite(R4,HIGH); D4=digitalRead(C1); // sets D4 equal to the input C1 D5=digitalRead(C2); // sets D5 equal to the input C2 D6=digitalRead(C3); // sets D6 equal to the input C3 D7=digitalRead(C4); // sets D7 equal to the input C4 if(D4==LOW) { lcd.print("7"); // prints '7' } else { if(D5==LOW) { lcd.print("8"); // prints '8' } else { if(D6==LOW) { lcd.print("9"); // prints '9' } else { if(D7==LOW) { lcd.print("/"); // prints '/' } }}} digitalWrite(R1,HIGH); // Drive R1 to HIGH digitalWrite(R2,LOW); // Drive R2 to LOW digitalWrite(R3,HIGH); // Drive R3, R4 to HIGH digitalWrite(R4,HIGH); D4=digitalRead(C1); // sets D4 equal to the input C1 D5=digitalRead(C2); // sets D5 equal to the input C2 D6=digitalRead(C3); // sets D6 equal to the input C3 D7=digitalRead(C4); // sets D7 equal to the input C4 if(D4==LOW) { lcd.print("4"); // prints '4' } else { if(D5==LOW) { lcd.print("5"); // prints '5' } else { if(D6==LOW) { lcd.print("6"); // prints '6' } else { if(D7==LOW) { lcd.print("X"); // prints 'X' } }}} digitalWrite(R1,HIGH); // Drive R1, R2 to HIGH digitalWrite(R2,HIGH); digitalWrite(R3,LOW); // Drive R3 to LOW digitalWrite(R4,HIGH); // Drive R4 to HIGH D4=digitalRead(C1); // sets D4 equal to the input C1 D5=digitalRead(C2); // sets D5 equal to the input C2 D6=digitalRead(C3); // sets D6 equal to the input C3 D7=digitalRead(C4); // sets D7 equal to the input C4 if(D4==LOW) { lcd.print("1"); // prints '1' } else { if(D5==LOW) { lcd.print("2"); // prints '2' } else { if(D6==LOW) { lcd.print("3"); // prints '3' } else { if(D7==LOW) { lcd.print("-"); // prints '-' } }}} digitalWrite(R1,HIGH); // Drive R1, R2, R3 to HIGH digitalWrite(R2,HIGH); digitalWrite(R3,HIGH); digitalWrite(R4,LOW); // Drive R4 to LOW D4=digitalRead(C1); // sets D4 equal to the input C1 D5=digitalRead(C2); // sets D5 equal to the input C2 D6=digitalRead(C3); // sets D6 equal to the input C3 D7=digitalRead(C4); // sets D7 equal to the input C4 if(D4==LOW) { lcd.print(" "); // prints nothing } else { if(D5==LOW) { lcd.print("0"); // prints '0' } else { if(D6==LOW) { lcd.print("="); // prints '=' } else { if(D7==LOW) { lcd.print("+"); // prints '+' } }}} }